// 需要登录的界面
let needLogin = [
	"/pages/search/search",
	"/pages/car/caseDetail",
	"/pages/product/new-product",
	"/pages/dynamic/detail",
	"/pages/my/compontents/mySetting",
	"/pages/my/applyShop",
	"/pages/my/compontents/myCollection",
	"/pages/my/compontents/myCase",
	"/pages/car/newCase",
	'/pages/dynamic/dynamic',
	'/pages/my/compontents/myProblem',
	'/pages/car/case',
	'/pages/car/quote',
	'/pages/product/product',
	'/pages/my/my',
	'/pages/search/shop'
];
// 拦截类型
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];

const install = (Vue,vm) => {
	list.forEach(item => {
		uni.addInterceptor(item, {
			invoke(e) {
				const token = vm.$store.state.phone_login_token;
				const url = e.url.split('?')[0];
				if (needLogin.includes(url) && !token) {
					uni.showToast({
						title: '该页面需要登录才能访问，请先登录',
						icon: 'none'
					});
					uni.navigateTo({
						url: "/pages/my/compontents/wxLogin?nextUrl="+e.url
					});
					return false;
				}
				return true;
			}
		});
	});
}

export default {
	install
}